//
// File:	ParserFile.cpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	02/02/2010 at 07:56:39
// Purpose:	
//
#include "Parser.hpp"

const std::size_t	Parser::File::stBufferSize = 128;

//------------------------------------------------------------------
// Get File Contents
//------------------------------------------------------------------
bool Parser::File::GetContents(const std::string &filePath, std::string &bufferTarget)
{
	std::ifstream ifs(filePath.c_str());
	if (ifs.is_open() == false)
		return false;
	while (!ifs.eof())
	{
		char tmpfilebuffer[stBufferSize + 1] = {0};
		ifs.read(tmpfilebuffer, stBufferSize);
		bufferTarget += tmpfilebuffer;
	}
	ifs.close();
	return true;
}

//------------------------------------------------------------------
// Write Contents to File
//------------------------------------------------------------------
bool Parser::File::WriteContents(const std::string &filePath, const std::string &buffer)
{
	std::ofstream ofs(filePath.c_str());
	if (ofs.is_open() == false)
		return false;
	ofs.write(buffer.c_str(), buffer.size());
	ofs.close();
	return true;
}
